﻿namespace MyTRCP.Common.MyProtocol
{
    public class BridgeAuthPayload : BitWalkableObj//bridge->client
    {
        public Guid SessionId
        {
            get
            {
                return new Guid(SessionIdBytes);
            }
            set
            {
                SessionIdBytes = value.ToByteArray();
            }
        }
        public byte[] SessionIdBytes { get; set; } = new byte[16];
        public ushort BridgeIdAuthResponseLength { get; set; }
        public byte[] BridgeIdAuthResponse { get; set; } = [];
        public BridgeAuthPayload() { }
        public BridgeAuthPayload(byte[] data) : base(data) { }
        public override BitWalker ReadFromBitWalker(BitWalker bw)
        {
            SessionIdBytes = bw.ReadBytes(16);
            BridgeIdAuthResponseLength = (ushort)bw.ReadBits(16);
            BridgeIdAuthResponse = bw.ReadBytes(BridgeIdAuthResponseLength);
            return bw;
        }

        public override BitWalker WriteToBitWalker(BitWalker bw)
        {
            return bw
                .WriteBytes(SessionIdBytes)
                .WriteBits(BridgeIdAuthResponseLength, 16)
                .WriteBytes(BridgeIdAuthResponse);
        }
    }
}